import React from "react";
import { useSelector, useDispatch } from "react-redux";

const List = () => {
  // const list = useSelector((state) => {
  //   console.log(state);
  //   return state.list;
  // });

  // 添加了模块化以后，获取数据的时候，需要加模块名
  const list = useSelector((state) => state.list2.list);

  const dispatch = useDispatch();

  return (
    <ul>
      {list.map((item) => (
        <li key={item._id}>
          {item.title} -{" "}
          <button onClick={() => dispatch({ type: "remove", id: item._id })}>
            删除
          </button>
        </li>
      ))}
    </ul>
  );
};

export default List;
